<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/11/2
 * Time: 17:24
 */

namespace App\Admin\Models;

/**
 * App\Admin\Models\TimelineConfigModel
 *
 * @property int $timeline_id 时间线ID
 * @property int $order 排序
 * @property string $title_zh 标题-中文
 * @property string $title_en 标题-英文
 * @property \Illuminate\Support\Carbon $created_at 创建时间
 * @property \Illuminate\Support\Carbon $updated_at 最后更新时间
 * @method static \Illuminate\Database\Eloquent\Builder|TimelineConfigModel newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|TimelineConfigModel newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|TimelineConfigModel query()
 * @method static \Illuminate\Database\Eloquent\Builder|TimelineConfigModel whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|TimelineConfigModel whereOrder($value)
 * @method static \Illuminate\Database\Eloquent\Builder|TimelineConfigModel whereTimelineId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|TimelineConfigModel whereTitleEn($value)
 * @method static \Illuminate\Database\Eloquent\Builder|TimelineConfigModel whereTitleZh($value)
 * @method static \Illuminate\Database\Eloquent\Builder|TimelineConfigModel whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class TimelineConfigModel extends BaseModel
{
    protected $table = 'admin_timeline_config';

    protected $primaryKey = 'timeline_id';

    public static function getConfigList()
    {
        $list = static::select(['timeline_id', 'title_zh', 'title_en'])->orderBy('order', 'asc')->orderBy('timeline_id', 'desc')->get();

        return !empty($list) ? json_decode(json_encode($list), true) : [];
    }

    public static function getConfigById(int $id)
    {
        $item = static::find($id);

        return $item ? json_decode(json_encode($item), true) : [];
    }
}
